//---------------------------------------------------------------------------
// * SearchResultVec
//--------------------------------------------------------------------------- 
// 
// 
void
SearchResultVec::FindLongestContiguousSpan(long &bestStart,long &bestEnd)
{

  // Sort the list into something easy to work with. 
  // First sort by location. 
  sort(this->begin(),this->end(),cmpBySubjectLocation);
  
  // then sort by whether result is for a forward or reverse sample
  stable_sort(this->begin(),this->end(),cmpByFwdRev);

  this->Print(cout);

  bestStart=0;
  bestEnd=0;
  int matchCount = 0,bestMatchCount = 0;
  long start = 0,end = 0;

  for(int r = 0;r < (*this).size();r++){
	 // If we are looking for a start
	 if (start == 0){
		if ((*this)[r].mIdentitiesNum >0){
		  start = (*this)[r].mSubjectLocation;
		  matchCount++;
		}
	 }else{
		// As long as there is a match, update end to point to that latest match
		if ((*this)[r].mIdentitiesNum > 0){
		  end = (*this)[r].mSubjectLocation;
		  matchCount++;
		}else{

		  // When there fails to be a match, evaluate whether the current start-end 
		  // pair is a bigger span than the biggest seen so far. 
		  if (matchCount > bestMatchCount){
			 cout<<(*this)[r].mQueryName<<" bestCount="<<matchCount<<endl;
			 bestMatchCount = matchCount;
			 bestStart = start;
			 bestEnd = end;
		  }

		  // Indicate that we are looking for a new stard and end. 
		  matchCount = 0;
		  start= 0; 
		  end= 0;
		}
	 }
  }
}
